package cn.edu.scau.cmi.xiehaizhou.composite.safe;

import java.util.List;

public class Organization extends OrganizationOrPerson{
	//构造函数
	public Organization()
	{
		this.name = "新建组织";
		fatherOrganization = null;
	}
	public Organization(String name, Organization father)
	{
		this.name = name;
		fatherOrganization = father;
	}
	
	public boolean AddPerson(String name)
	{
		if(childrenList!=null)
		for (OrganizationOrPerson OorP : childrenList) {
			if(OorP.getName().equals(name))
				return false;
		}
		Person child =  new Person(name,this);
		childrenList.add(child);
		return true;
	}
	public boolean AddOrganization(String name)
	{
		if(childrenList!=null)
		for (OrganizationOrPerson OorP : childrenList) {
			if(OorP.getName().equals(name))
				return false;
		}
		Organization child = new Organization(name,this);
		childrenList.add(child);
		return true;
	}
	public void Delete(String name)
	{
		if(childrenList!=null)
		for (OrganizationOrPerson OorP : childrenList) {
			if(OorP.getName().equals(name))
			{
				childrenList.remove(OorP);
				break;
			}
		}
	}
	@SuppressWarnings("null")
	public List<String> getChildren()
	{
		List<String> childrenStrings = null;
		if(childrenList!=null)
		for (OrganizationOrPerson OorP : childrenList) {
			childrenStrings.add(OorP.getName());
		}
		return childrenStrings;
	}
}
